﻿using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Task.Quartz;
using Task.Quartz.Example;
using Task.DB;
using System.IO;
using System.Security.Cryptography;
using Task.Log;

namespace Task.Test
{
    class Program
    {
        //private static Logger logger = LogManager.GetCurrentClassLogger(typeof(Program));
        static void Main(string[] args)
        {
            //string zipfileName = @"C:\Users\Administrator\Desktop\框架\quartz\Quatrz.Task\Appstart\downFile\wt.zip";
            //int iUnZipResult = Task.Util.ZipHelper.UnZipFile(zipfileName, zipfileName.Replace(".zip", ""));
            //if (iUnZipResult != 1)
            //{
            //}

            Task.Log.LogHelper.Info("启动", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            MyJobTests.Instance.OnStartServer();

            //FileFile(@"D:\360Downloads\111.jpg");
            //Console.ReadLine();
            //NlogLogger logger = new NlogLogger("测试");
            //logger.Trace("Sample trace message");
            //logger.Debug("Sample debug message");
            //logger.Info("Sample informational message");
            //logger.Error("Sample error message");
            //logger.Fatal("Sample fatal error message");
        }

        public static void FileFile(string filename, int timesToWrite = 2)
        {
            try
            {
                if (File.Exists(filename))
                {
                    //设置文件的属性为正常，这是为了防止文件是只读
                    File.SetAttributes(filename, FileAttributes.Normal);
                    //计算扇区数目
                    double sectors = Math.Ceiling(new FileInfo(filename).Length / 512.0);
                    // 创建一个同样大小的虚拟缓存
                    byte[] dummyBuffer = new byte[512];
                    // 创建一个加密随机数目生成器
                    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                    // 打开这个文件的FileStream
                    FileStream inputStream = new FileStream(filename, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
                    for (int currentPass = 0; currentPass < timesToWrite; currentPass++)
                    {
                        // 文件流位置
                        inputStream.Position = 0;
                        //循环所有的扇区
                        for (int sectorsWritten = 0; sectorsWritten < sectors; sectorsWritten++)
                        {
                            //把垃圾数据填充到流中
                            rng.GetBytes(dummyBuffer);
                            // 写入文件流中
                            inputStream.Write(dummyBuffer, 0, dummyBuffer.Length);
                        }
                    }
                    // 清空文件
                    inputStream.SetLength(0);
                    // 关闭文件流
                    inputStream.Close();
                    // 清空原始日期需要
                    DateTime dt = new DateTime(2037, 1, 1, 0, 0, 0);
                    File.SetCreationTime(filename, dt);
                    File.SetLastAccessTime(filename, dt);
                    File.SetLastWriteTime(filename, dt);
                    // 删除文件
                    File.Delete(filename);
                }
            }
            catch (Exception)
            {
            }
        }
    }
}
